
const { doSearchByKeyword } = require('./proccessor/doSearchPluginByKeyword');
const { doSearchByFolder } = require('./proccessor/doSearchPluginByFolder');
const { doSearchByFile } = require('./proccessor/doSearchPluginByFile');
const { onEmit } = require('../baseService/broadService/processor/broadcastProcessor');
const { asyncTopicConstants } = require('../../common/constans/asyncTopicContans');


exports.searchPlugin = async function (request) {
    onEmit(asyncTopicConstants.resetRunPlugin)
    await doSearch(request)
}

async function doSearch(request) {
    let theRequest = request
    theRequest.input = parseKeyword(request.input)
    const type = theRequest.type


    if (type == "keyword") {
        doSearchByKeyword(theRequest)
    } else if (type == "folder") {
        doSearchByFolder(theRequest)
    } else if (type == "file") {
        doSearchByFile(theRequest)
    }
}



function parseKeyword(keyword) {
    if (keyword == null) return null
    // 用于处理搜索关键字，避免sql注入
    let newKeyword = keyword
    newKeyword = newKeyword.replace("'", "")
    return newKeyword
}